package com.wy.System.Print.ideaControlConsole;

import com.wy._05Random.randomFile.Enum.FileType;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;

//能画一个太极。
public class YingYangGraphics extends JComponent {
    public static void main(String[] args) throws IOException {
        BufferedImage bufferedImage = new BufferedImage(300,300, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = bufferedImage.createGraphics();
        YingYangGraphics yingYangGraphics = new YingYangGraphics();
        yingYangGraphics.paintComponent(graphics);
        ImageIO.write(bufferedImage,"jpg",new File("E:\\temp\\pic\\1.jpg"));
    }

    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//        g2.drawImage(getImage(), 0, 0, image.getWidth(), image.getHeight(), null);

        Shape lefthalfCirle = new Ellipse2D.Double(10, 10, 300, 300);
//        R = 150
        Shape righthalfCircle = new Ellipse2D.Double(10, 10, 300, 300);
//        R = 150
        Shape innerCircle1 = new Ellipse2D.Double(85, 10, 150, 150);
//        R / 2 = 75
        Shape innerCircle2 = new Ellipse2D.Double(85, 160, 150, 150);
//        R = 150
        Shape rectangel1 = new Rectangle2D.Double(160, 10, 150, 300);
        Shape rectangel2 = new Rectangle2D.Double(10, 10, 150, 300);
        Area left = new Area(lefthalfCirle);
        Area right = new Area(righthalfCircle);
        Area area11 = new Area(rectangel1);
        Area area22 = new Area(rectangel2);
        left.subtract(area11);
        right.subtract(area22);
        Area inner1 = new Area(innerCircle1);
        Area inner2 = new Area(innerCircle2);
        left.add(inner1);
        left.subtract(inner2);
        right.add(inner2);
        right.subtract(inner1); //trick is here !!!
//        create minor circle here !!!
        Shape minorWhiteCircle = new Ellipse2D.Double(150, 70, 20, 20);
//        ++60
        Shape innerBlackCircle = new Ellipse2D.Double(150, 230, 20, 20);
//        R = 150
//        draw two big frame shape here...
        g2.setPaint(Color.WHITE);
        g2.fill(left);
        g2.setPaint(Color.BLACK);
        g2.fill(right);
//        draw minor circle here !!!
        g2.fill(minorWhiteCircle);
        g2.setPaint(Color.WHITE);
        g2.fill(innerBlackCircle);

    }

//    public static void main(String[] args) {
//        JFrame frame = new JFrame("Test Panel");
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.getContentPane().setLayout(new BorderLayout());
////        Display the window.
//        frame.getContentPane().add(new YingYangGraphics(), BorderLayout.CENTER);
//        frame.setPreferredSize(new Dimension(330, 350));
//        frame.pack();
//        frame.setVisible(true);
//    }
}